/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <div class="subject">
        <h3>分销关系</h3>
        <h5>查看代理商层级关系</h5>
      </div>
    </div>
    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>查看代理商层级关系。</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <div class="mDiv">
      <div class="ftitle">
        <h3>分销人员列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
      <div title="上级区域" v-if="parentUser.user_id" style="width:auto;float:left;margin-left:20px">
        上级用户 ({{parentUser.user_id}}:
        <span v-if="parentUser.nickname">{{parentUser.nickname}}</span>
        <span v-else-if="parentUser.email">{{parentUser.email}}</span>
        <span v-else>{{parentUser.mobile}}</span>)
      </div>
      <div class="fbutton" v-if="parentUser.user_id">
        <div class="add" @click="toParent()">
          <span>
            <i class="el-icon-top" /> 返回分销上级
          </span>
        </div>
      </div>
    </div>
    <div class="tablebox" v-if="tableData">
      <el-table :data="tableData" ref="multipleTable" style="width: 100%;">
        <el-table-column label="会员ID" prop="user_id" width="120"></el-table-column>
        <el-table-column label="会员名称" width="150">
          <template slot-scope="scope">
            <span v-if="scope.row.nickname">{{scope.row.nickname}}</span>
            <span v-else-if="scope.row.email">{{scope.row.email}}</span>
            <span v-else>{{scope.row.mobile}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <el-button size="small" icon="el-icon-zoom-in" @click="toChildren(scope.row)">查看下级</el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { getUserList, getUser } from "@/utils/api";
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 10,
      parentUser: {
        user_id: 0
      }
    };
  },
  components: {},
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      getUserList({
        first_leader: this.parentUser.user_id,
        p: that.currentPage,
        size: that.pageSize
      }).then(function(res) {
        that.tableData = res.records;
        that.totalCount = res.total;
      });
    },
    refresh() {
      this.getPage();
      this.$message({
        type: "success",
        message: "刷新成功！"
      });
    },
    toParent() {
      var that = this;
      getUser({
        user_id: this.parentUser.first_leader
      }).then(function(res) {
        that.parentUser = res;
        that.getPage();
      });
    },
    toChildren(row) {
      this.parentUser = row;
      this.currentPage = 1;
      this.getPage();
    }
  }
};
</script>

<style scoped>
</style>
